/**
 * Created by zhijie on 2016/12/19.
 */
/**
 * Created by hezhijie on 2016/11/22.
 */
var app = angular.module("app", [
    "ui.router",    //路由
    "oc.lazyLoad",  //延迟加载
    "ngCookies"
]);


/*
 * 加载配置,配置路由
 * 路由配置方式
 * $stateProvider.state("state", {})
 * 其中"state"为路由状态，为一个页面设置一个状态，不设置重复状态。
 *
 * {},路由参数
 * 常用参数
 * url : 页面跳转后url，配置后可在浏览器上看到。浏览器输入对应地址也可访问到
 * templateUrl : 模版/页面路径
 * template : 模版内容，可为html代码
 * views : 多视图配置，key对应ui-view="name"。不配置将加载<div ui-view></div>中
 * 深入了解可详见http://bubkoo.com/2014/01/01/angular/ui-router/guide/multiple-named-views/
 * resolve :
 *
 *
 *
 * ["$stateProvider", "$urlRouterProvider", function($a, $b){}]  DI，自动注入。修改配置方式，用于代码压缩时方便
 */
app.config(["$stateProvider", "$urlRouterProvider", function ($state, $urlRouter) {

    $urlRouter.otherwise('/payPage');
    $state.state("payPage", {
        url: '/payPage/:merchantId',
        templateUrl: basePath + '/modules/order/payPage.html',
        resolve: {
            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                return $ocLazyLoad.load([
                    basePath + "/modules/order/js/payPage.js"
                ]);
            }]
        }
    })

}]);


app.controller("AppCtrl", ['$scope',
    function ($scope) {
        $scope.transference = transference;
        $scope.transformBool = function (val) {
            if (val == true || 'true' == val) {
                return "是"
            } else {
                return "否"
            }
        }
    }]);

/**
 * app启动后执行，常用于配置全局变量
 */
app.run([
    "$rootScope",
    "$state",
    "$stateParams",
    "$location",
    "$cookieStore",
    function ($rootScope, $state, $stateParams, $location, $cookieStore) {
        global.$rootScope = $rootScope;
        $rootScope.basePath = basePath;
        $rootScope.$rootScope = $rootScope;
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;
        $rootScope.$location = $location;
        $rootScope.$cookieStore = $cookieStore;
        $rootScope.back = function () {
            history.back();
        }
    }
]);